import request from '@/utils/request'

// 模型管理API
export function getModels(params) {
  return request({
    url: '/api/models/models/',
    method: 'get',
    params
  })
}

export function getModelDetail(id) {
  return request({
    url: `/api/models/models/${id}/`,
    method: 'get'
  })
}

export function createModel(data) {
  return request({
    url: '/api/models/models/',
    method: 'post',
    data
  })
}

export function updateModel(id, data) {
  return request({
    url: `/api/models/models/${id}/`,
    method: 'put',
    data
  })
}

export function deleteModel(id) {
  return request({
    url: `/api/models/models/${id}/`,
    method: 'delete'
  })
}

export function activateModel(id) {
  return request({
    url: `/api/models/models/${id}/activate/`,
    method: 'post'
  })
}

export function getActiveModel() {
  return request({
    url: '/api/models/models/active_model/',
    method: 'get'
  })
}

export function getModelTrainingJobs(params) {
  return request({
    url: '/api/models/training-jobs/',
    method: 'get',
    params
  })
}

export function getModelTrainingJobDetail(id) {
  return request({
    url: `/api/models/training-jobs/by-job-id/${id}/`,
    method: 'get'
  })
}

export function cancelModelTrainingJob(id) {
  return request({
    url: `/api/models/training-jobs/by-job-id/${id}/cancel/`,
    method: 'post'
  })
}

export function getModelPredictions(params) {
  return request({
    url: '/api/models/predictions/',
    method: 'get',
    params
  })
}

export function getModelPredictionDetail(id) {
  return request({
    url: `/api/models/predictions/${id}/`,
    method: 'get'
  })
}

// 模型服务API
export function trainModel(data) {
  return request({
    url: '/api/models/service/train/',
    method: 'post',
    data
  })
  .then(response => {
    console.log('训练模型成功:', response);
    return response;
  })
  .catch(error => {
    console.error('训练模型失败:', error);
    console.error('请求数据:', data);
    throw error;
  });
}

export function predictCustomer(data) {
  return request({
    url: '/api/models/service/predict/',
    method: 'post',
    data
  })
}

export function getModelTypes() {
  return request({
    url: '/api/models/service/model_types/',
    method: 'get'
  })
}

export function getModelMetrics() {
  return request({
    url: '/api/models/service/model_metrics/',
    method: 'get'
  })
} 